﻿using AutoMapper;
using MediatR;
using WMS.API.Application.Command.StocktakingManagement;
using WMS.API.Application.Command.WarehouseManagement.WarehouseCommand;
using WMS.Domain.Entities.WarehouseManagement;
using WMS.ErrorCode;
using WMS.Interfactructure.Interfaces;

namespace WMS.API.Application.CommandHandlers.WarehouseManagement.Handler
{
    public class AddWarehouseCommandHandler : IRequestHandler<AddWarehouseCommand, APIResult<int>>
    {
        private readonly IBaseRepository<InboundListModel> _inbounbaseRepository;
        private readonly IMapper mapper;

        public AddWarehouseCommandHandler(IBaseRepository<InboundListModel> InbounbaseRepository,IMapper mapper)
        {
            _inbounbaseRepository = InbounbaseRepository;
            this.mapper = mapper;
        }

        public async Task<APIResult<int>> Handle(AddWarehouseCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>("添加入库成功");
            result.Code=ResultCode.Success;
            InboundListModel inboundListModel=mapper.Map<InboundListModel>(request);
            await _inbounbaseRepository.AddAsync(inboundListModel);
            return await Task.FromResult(result);
        }
    }
}
